const app = getApp()
import http from "../utils/http"
import config from "../utils/config"

Component({
  data: {
    selected: 0,
    color: "#999999",
    selectedColor: "#47474C",
    backgroundColor: "#fff",
    list: [
      {
        "pagePath": "/pages/index/index",
        "text": "首页",
        "iconPath": "/static/tabbar/home.png",
        "selectedIconPath": "/static/tabbar/home_active.png"
      },
      {
        "pagePath": "/pages/classify/classify",
        "text": "分类",
        "iconPath": "/static/tabbar/classify.png",
        "selectedIconPath": "/static/tabbar/classify_active.png"
      },
      {
        "bulge": true,
        "pagePath": "/pages/activity/activity",
        // "pagePath": "/pages/servers/servers",
        // "text": "服务者",
        "iconPath": "/static/tabbar/servers.png",
        "selectedIconPath": "/static/tabbar/servers_active.png"
      },
      {
        "pagePath": "/pages/shop/shop",
        // "pagePath": "/pages/business/business",
        "text": "商城",
        "iconPath": "/static/tabbar/business.png",
        "selectedIconPath": "/static/tabbar/business_active.png"
      },
      {
        "pagePath": "/pages/my/my",
        "text": "我的",
        "iconPath": "/static/tabbar/my.png",
        "selectedIconPath": "/static/tabbar/my_active.png"
      }
    ],
    timeOutTemp: null,
  },
  lifetimes: {
    attached() {
      // 组件加载完成后处理逻辑
      this.getMenuIconByGlobalData();
    }
  },
  methods: {
    switchTab(e) {
      const data = e.currentTarget.dataset;
      wx.switchTab({ url: data.path });
    },
    getMenuIconByGlobalData() {
      if (!app.globalData.menuIcon) {
        // 如果menuIcon没有值，就轮询获取
        this.timeOutTemp = setTimeout(() => {
          this.getMenuIconByGlobalData();
        }, 200)
        return;
      }

      clearTimeout(this.timeOutTemp);
      const path = config.cdn + app.globalData.menuIcon;
      this.data.list[2].iconPath = path;
      this.data.list[2].selectedIconPath = path;
      this.setData({
        list: this.data.list
      })
    },
  }
})
